<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;

class HomeController extends Controller
{
    public function home(Request $Request)
    {
        //特价促销
            $data = DB::table('shop_active')
                  ->whereIn('id',array('160','161','162','163'))
                  ->select('id','title','price','oldPrice')
                  ->get();
                  // dd($data);
            foreach ($data as $k=>$v){
                $path = DB::table('shop_activepics')->where('aid',$v->id)->select('path')->first();
                $data[$k]->path = $path->path;
            }
              // dd($data);
      // 本月热销
          $data2 = DB::table('shop_active')
                ->whereIn('id',array('164','165','166','167'))
                ->select('id','title','price','oldPrice')
                ->get();
            // dd($data2);
          foreach ($data2 as $k=>$v){
            $path = DB::table('shop_activepics')->where('aid',$v->id)->select('path')->first();
            $data2[$k]->path = $path->path;
          }

      // 清仓处理
        $data3 = DB::table('shop_active')
                ->whereIn('id',array('168','169','170'))
                ->select('id','title','price','oldPrice')
                ->get();
        foreach ($data3 as $k=>$v){
            $path = DB::table('shop_activepics')->where('aid',$v->id)->select('path')->first();
            $data3[$k]->path = $path->path;
          }

      // 限时折扣
        $data4 = DB::table('shop_active')
                ->whereIn('id',array('171','172','173'))
                ->select('id','title','price','oldPrice')
                ->get();
        foreach ($data4 as $k=>$v){
            $path = DB::table('shop_activepics')->where('aid',$v->id)->select('path')->first();
            $data4[$k]->path = $path->path;
          }

      // 精品推荐
         $data5 = DB::table('shop_active')
                ->where('id',rand(174,180))
                ->select('id','title','price','oldPrice')
                ->get();
              // dd($data5);
        foreach ($data5 as $k=>$v){
            $path = DB::table('shop_activepics')->where('aid',$v->id)->select('path')->first();
            $data5[$k]->path = $path->path;
          }

        // 轮播
      $res = DB::table('shop_carouselpics')->where('status',1)->get();
      // dd($res);
       // 分配模板 解析变量
       return view('welcome',['data'=>$data,'data2'=>$data2,'data3'=>$data3,'data4'=>$data4,'data5'=>$data5,'res'=>$res]);
    }

    
}
